package cpi.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cpi.entity.Collection;
import cpi.service.CollectionService;
import cpi.tools.CommonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (Collection)表控制层
 *
 * @author makejava
 * @since 2022-07-18 14:47:29
 */
@CrossOrigin
@RestController
@RequestMapping("collection")
public class CollectionController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private CollectionService collectionService;

    @ApiOperation("获取按省份全部收藏")
    @GetMapping("/selectProvince")
    public CommonResult selectProvince() {
        return CommonResult.success(collectionService.selectProvince());
    }

    @ApiOperation("获取按类别全部收藏")
    @GetMapping("/selectType")
    public CommonResult selectType() {
        return CommonResult.success(collectionService.selectType());
    }

    @ApiOperation("通过ID获取")
    @GetMapping("getByid")
    public CommonResult getByid(int id){
        return CommonResult.success(collectionService.getByid(id));
    }

    @ApiOperation("收藏")
    @PostMapping("/collecting")
    public CommonResult collect(@RequestBody Collection collection){
        System.out.println(collection);
        return CommonResult.success(collectionService.collect(collection.getCollectname(),collection.getType(),collection.getProvince(),collection.getTime()));
    }

    @ApiOperation("删除")
    @PostMapping("/delete")
    public CommonResult delete(@RequestBody Collection collection){
        return CommonResult.success(collectionService.delete(collection.getType(),collection.getProvince(),collection.getTime()));
    }

    @ApiOperation("按省份是否收藏")
    @GetMapping("/isProvince")
    public CommonResult isProvince(String type,int time){
        return CommonResult.success(collectionService.isProvince(type,time));
    }

    @ApiOperation("按类别是否收藏")
    @GetMapping("/isType")
    public CommonResult isType(String province,int time){
        return CommonResult.success(collectionService.isType(province,time));
    }
}

